package cn.yikaojiuguo.student.ui.my;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.yikaojiuguo.student.R;
import cn.yikaojiuguo.student.app.YiKaoApplication;
import cn.yikaojiuguo.student.ui.base.BaseFragment;
import cn.yikaojiuguo.student.ui.base.CustomerActionBarActivity;

public class MyTeacherActivity extends CustomerActionBarActivity {

    @Bind(R.id.stl)
    SlidingTabLayout mStl;
    @Bind(R.id.vp)
    ViewPager mVp;

    private List<BaseFragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "已购买", "已关注"};

    public static Intent newIntent() {
        Intent intent = new Intent(YiKaoApplication.getInstance(),MyTeacherActivity.class);
        return intent;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_teacher);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mFragments.add(new MyPayedTeacherFragment());
        mFragments.add(new MyFocusTeacherFragment());
        mVp.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        mStl.setViewPager(mVp,mTitles);
    }

    private class MyPagerAdapter extends FragmentStatePagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public BaseFragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
